<?php
namespace app\dsadmin\controller;
use app\common\model\DwzModel;
use think\Db;
use think\Cache;

class Dwz extends Base
{
    public function index()
    {
        
        $key  = input('key');
        $map = [];
        if ($key && $key !== "")
        {
            $map['userid|ddh|dwz|sdwz|dwz1'] = ['like', "%" . $key . "%"];
        }
        $Nowpage = input('get.page') ? input('get.page'):1;
        $limits = 20; // 获取总条数
        $count = Db::name('dwz')->where($map)->count(); //计算总页面
        $allpage = intval(ceil($count / $limits));
        $ename = new DwzModel();
        $lists = $ename->getEnamesByWhere($map, $Nowpage, $limits);
       
        $this->assign('Nowpage', $Nowpage); //当前页
        $this->assign('allpage', $allpage); //总页数 
        $this->assign('val', $key);
        if (input('get.page'))
        {
            return json($lists);
        }
        return $this->fetch();
    }
    
    
     ///短连接
    
    public function lindex(){
      
        $map = [];
       
        $Nowpage = input('get.page') ? input('get.page'):1;
        $limits = 10;
        $count  = 10; //计算总页面
        $allpage = intval(ceil($count / $limits));
        $lists = Db::name('lianjie')->where("isinfo = 1")->order('state desc')->select();
        $this->assign('Nowpage', $Nowpage); //当前页
        $this->assign('allpage', $allpage); //总页数 
      
        if (input('get.page'))
        {
            return json($lists);
        }

        return $this->fetch();
    }
    
    
      public function member_status()
    {
        $id = input('param.id');
        $status = Db::name('lianjie')->where('id', $id)->value('state'); //�жϵ�ǰ״̬��� 
        if ($status == 1)
        {
            $flag = Db::name('lianjie')->where('id', $id)->setField(['state' => 0]);
         
            return json(['code' => 1, 'data' => $flag['data'], 'msg' => '禁用成功']);
        }
        else
        {
            $flag = Db::name('lianjie')->where('id', $id)->setField(['state' => 1]);
          
            return json(['code' => 1, 'data' => $flag['data'], 'msg' => '开启成功']);
        }
    }
    
    
    public function dwz_edit(){
       
        if (request()->isAjax())
        {
            $param = input('post.');
            if (intval($param['rate']) < 0)
            {
                $this->error("不能小于0");
            }
            
            if (intval($param['rate']) > 100)
            {
                $this->error("不能大于100");
            }
            
            Db::name('lianjie')->where(['id' => $param['id']])->update(['rate' => $param['rate']]);
            return json(['code' => 1, 'data' => '', 'msg' => '修改成功']);
        }

        $id   = input('param.id');
        $info = Db::name('lianjie')->where(['id'=>$id])->find();

        $this->assign([
            'info' => $info,
            ]);
        return $this->fetch();
    }

 

    public function del()
    {
        $id = input('param.id');
        $role = new EnameModel();
        $flag = $role->delEname($id);
        return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
    }

    public function del_wxdanger()
    {
        $role = new EnameModel();
        $flag = $role->delEname_wxdanger();
        return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
    }

    public function status()
    {
        $id = input('param.id');
        $status = Db::name('dwz')->where('id', $id)->value('status'); //判断当前状态情况
        if ($status == 1)
        {
            $flag = Db::name('dwz')->where('id', $id)->setField(['status' => 0]);
            $infos = Db::name('dwz')->where(['id' => $id])->find();
            
            Cache::store('redis')->set($infos['jiami'],json_encode($infos));
            return json(['code' => 1, 'data' => 1, 'msg' => '1']);
        }
        else
        {
            $flag = Db::name('dwz')->where('id', $id)->setField(['status' => 1]);
            
            $infos = Db::name('dwz')->where(['id' => $id])->find();
            
            Cache::store('redis')->set($infos['jiami'],json_encode($infos));
            
            return json(['code' => 0, 'data' => 0, 'msg' => '2']);
        }
    }
  

}
